from tkinter import Frame, Radiobutton, IntVar, W


class DefinitionGui(Frame):
	def __init__(self, root, listener):
		super().__init__(root)

		self.listener = listener

		self.definition_frame = Frame(self)
		self.definition_frame.grid(row=0, column=0, sticky=W)

		self.content_frame = Frame(self)
		self.content_frame.grid(row=0, column=1, columnspan=3, sticky=W)

		self.definitions = []
		self.selected = IntVar()
		# self.content_frame.configure(background='black')

	def _set_definitions(self, definitions):
		self.definitions = definitions
		self.selected.set(-1)
		for index, definition in enumerate(definitions):
			button = Radiobutton(self.definition_frame, variable=self.selected, value=index, text=definition.get_text(), command=self._select)
			button.grid(row=index, column=0, sticky=W)

	def _select(self):
		self.listener.set_definition(self.definitions[self.selected.get()])
